package com.wd.cloud.applet.controller.manage;

import com.wd.cloud.applet.common.Response;
import com.wd.cloud.applet.common.exception.CustomException;
import com.wd.cloud.applet.config.CustomListResultConfig;
import com.wd.cloud.applet.entity.bo.SysDictInfoBO.SysDictInfoListBO;
import com.wd.cloud.applet.entity.bo.SysDictInfoBO.SysDictInfoSaveBO;
import com.wd.cloud.applet.entity.commons.RequestPrimaryKeyModel;
import com.wd.cloud.applet.entity.vo.SysDictInfoVO.SysDictInfoListVO;
import com.wd.cloud.applet.entity.vo.SysDictInfoVO.SysDictInfoKeyVO;
import com.wd.cloud.applet.service.ISysDictInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 字典表控制器
 * Created on 2023年04月23日
 * @author  <a href="mailto: 987707681@qq.com">hjx</a>
 * @version 1.0
 * Copyright (c) 2023年 代码生成器
 */
@Api(tags = "字典表控制器")
@RestController
@RequestMapping("/manage/sysDictInfo")
public class SysDictInfoController {
    @Resource
    private ISysDictInfoService sysDictInfoService;

    /**
     * 新增/编辑
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增/编辑")
    @PostMapping("/save")
    public Response save(@RequestBody SysDictInfoSaveBO dto) {
            if (sysDictInfoService.save(dto)>0) {
                return Response.ok();
            } else {
                throw new CustomException("操作失败", 101);
            }
    }
/**
* 删除操作
*
* @param dto
* @return
*/
@ApiOperation(value = "删除操作")
@PostMapping("/delByIdentify")
public Response delByIdentify(@RequestBody RequestPrimaryKeyModel dto) {
if (sysDictInfoService.deleteByPrimaryKey(dto) > 0) {
return Response.ok("删除成功");
} else {
throw new CustomException("操作失败", 101);
}
}
    /**
     * 获取分页列表数据
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "获取分页列表数据")
    @PostMapping("/getListPage")
    public Response<CustomListResultConfig<SysDictInfoListVO>> getListPage(@RequestBody SysDictInfoListBO params) {
        CustomListResultConfig<SysDictInfoListVO> selectByPageList = sysDictInfoService.selectByPageList(params);
            return Response.ok(selectByPageList);
    }

    /**
     * 根据ID获取实体数据
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "根据ID获取实体数据")
    @PostMapping("/getEntityByKey")
    public Response<SysDictInfoKeyVO> getEntityByKey(@RequestBody RequestPrimaryKeyModel dto) {
            SysDictInfoKeyVO model = sysDictInfoService.selectByPrimaryKey(dto);
            return Response.ok(model);
    }
}
